<?php

class LanguageService extends TService
{
	public function __construct()
	{
		$this->setID('language');
	}
	
	public function run()
	{
		parent::run();
		
		$language = $this->getRequest()->getServiceParameter();
		if(!$language)
			$language = 'en';
		
		$source = $this->Application->Globalization->getTranslationConfiguration()->itemAt('source');
		$messages_filename = 'messages.xml';
		
		$file_path = $source.'/'.$language.'/'.$messages_filename;
		$text = '';
		
		if(@file_exists($file_path))
		{
			$file_handler = fopen($file_path, "r");
			$text = fread($file_handler, filesize($file_path));
			fclose($file_handler);
			
			$this->getResponse()->setContentType('text/xml');
		}
		$this->getResponse()->write($text);
	}
}

?>